package com.lwy.unos.stuinfo.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lwy.unos.stuinfo.entity.ClassInfoEntity;
import com.lwy.unos.stuinfo.service.ClassInfoService;
import com.lwy.common.utils.PageUtils;
import com.lwy.common.utils.R;



/**
 * 
 *
 * @author weizhennan
 * @email weizhennan@gmail.com
 * @date 2020-11-05 19:54:44
 */
@RestController
@RequestMapping("stuinfo/classinfo")
public class ClassInfoController {
    @Autowired
    private ClassInfoService classInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = classInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
//    @RequestMapping("/info/{classId}")
//    public R info(@PathVariable("classId") Integer classId){
//		ClassInfoEntity classInfo = classInfoService.getById(classId);
//        return R.ok().put("classInfo", classInfo);
//    }

    @RequestMapping("/list/{gradeId}")
    public  List<ClassInfoEntity> classList(@PathVariable("gradeId") Integer gradeId){
        List<ClassInfoEntity> classInfoEntities = classInfoService.getBaseMapper().selectList(new QueryWrapper<ClassInfoEntity>().eq("grade_id", gradeId));
        return classInfoEntities;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ClassInfoEntity classInfo){
		classInfoService.save(classInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ClassInfoEntity classInfo){
		classInfoService.updateById(classInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] classIds){
		classInfoService.removeByIds(Arrays.asList(classIds));
        return R.ok();
    }

}
